enum JLPeripheralState {
  disconnected,
  connecting,
  connected,
  disconnecting,
  refuse,
  update
}

/// name : "WATCH_1"
/// state : 0
/// identifier : "176EAB6B-944F-E886-701C-2AEB52EDD556"
class JLPeripheralModel {
  String? _name;
  JLPeripheralState? _state;
  String? _identifier;
  String? _address;

  String? get name => _name;

  JLPeripheralState? get state => _state;

  String? get identifier => _identifier;

  String? get address => _address;

  JLPeripheralModel({String? name, JLPeripheralState? state, String? identifier, String? address}) {
    _name = name;
    _state = state;
    _identifier = identifier;
    _address = address;
  }

  JLPeripheralModel.fromJson(Map json) {
    _name = json["name"];
    switch (json["state"]) {
      case 0:
        _state = JLPeripheralState.disconnected;
        break;
      case 1:
        _state = JLPeripheralState.connecting;
        break;
      case 2:
        _state = JLPeripheralState.connected;
        break;
      case 3:
        _state = JLPeripheralState.disconnecting;
        break;
      default:
        _state = JLPeripheralState.disconnected;
        break;
    }
    _identifier = json.containsKey("identifier") ? json["identifier"] : null;
    _address = json.containsKey("address") ? json["address"] : null;
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["name"] = _name;
    switch (_state) {
      case JLPeripheralState.disconnected:
        map["state"] = 0;
        break;
      case JLPeripheralState.connecting:
        map["state"] = 1;
        break;
      case JLPeripheralState.connected:
        map["state"] = 2;
        break;
      case JLPeripheralState.disconnecting:
        map["state"] = 3;
        break;
      default:
        map["state"] = 0;
        break;
    }
    map["identifier"] = _identifier ?? '';
    map["address"] = _address ?? '';
    return map;
  }
}
